determine the local maximum and minimum